package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TPersonFile;
import com.ruoyi.system.service.ITPersonFileService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 人员档案 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-02-22
 */
@Controller
@RequestMapping("/system/tPersonFile")
public class TPersonFileController extends BaseController
{
    private String prefix = "system/tPersonFile";
	
	@Autowired
	private ITPersonFileService tPersonFileService;
	
	@RequiresPermissions("system:tPersonFile:view")
	@GetMapping()
	public String tPersonFile()
	{
	    return prefix + "/tPersonFile";
	}
	
	/**
	 * 查询人员档案列表
	 */
	@RequiresPermissions("system:tPersonFile:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TPersonFile tPersonFile)
	{
		startPage();
        List<TPersonFile> list = tPersonFileService.selectTPersonFileList(tPersonFile);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出人员档案列表
	 */
	@RequiresPermissions("system:tPersonFile:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TPersonFile tPersonFile)
    {
    	List<TPersonFile> list = tPersonFileService.selectTPersonFileList(tPersonFile);
        ExcelUtil<TPersonFile> util = new ExcelUtil<TPersonFile>(TPersonFile.class);
        return util.exportExcel(list, "tPersonFile");
    }
	
	/**
	 * 新增人员档案
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存人员档案
	 */
	@RequiresPermissions("system:tPersonFile:add")
	@Log(title = "人员档案", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TPersonFile tPersonFile)
	{		
		return toAjax(tPersonFileService.insertTPersonFile(tPersonFile));
	}

	/**
	 * 修改人员档案
	 */
	@GetMapping("/edit/{code}")
	public String edit(@PathVariable("code") String code, ModelMap mmap)
	{
		TPersonFile tPersonFile = tPersonFileService.selectTPersonFileById(code);
		mmap.put("tPersonFile", tPersonFile);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存人员档案
	 */
	@RequiresPermissions("system:tPersonFile:edit")
	@Log(title = "人员档案", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TPersonFile tPersonFile)
	{		
		return toAjax(tPersonFileService.updateTPersonFile(tPersonFile));
	}
	
	/**
	 * 删除人员档案
	 */
	@RequiresPermissions("system:tPersonFile:remove")
	@Log(title = "人员档案", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tPersonFileService.deleteTPersonFileByIds(ids));
	}
	
}
